from pymysql import connect

user='root'
passwd='123456'
port=3307
database='book_test'
host='127.0.0.1'



def get_book_list():

    sql = 'select * from book'
    data = select(sql)
    return data

def get_book_list_by_name(query):

    sql = f"select * from book where bookName like '%{query}%'"
    data=select(sql)
    return data


def select (sql):
    con = connect(host=host, user=user, passwd=passwd, database=database, port=port)
    cur = con.cursor()
    cur.execute(sql)
    data = cur.fetchall()
    con.close()
    cur.close()
    return data